function GAD_Etom_Mobility_and_Imobility_ER_CDFs(Mobility_and_ER_Data_Summary)
%% Compute ER CDFs during mobility & imobility for p-WT first
WT_Mobility_ER = [];
for n = 1:size(Mobility_and_ER_Data_Summary,2)
    if isempty(WT_Mobility_ER) && strcmp(Mobility_and_ER_Data_Summary(n).genotype, 'a5-i-WT')
        WT_Mobility_ER = Mobility_and_ER_Data_Summary(n).Session2_Cell_ER_During_Mobility;
    elseif ~isempty(WT_Mobility_ER) && strcmp(Mobility_and_ER_Data_Summary(n).genotype, 'a5-i-WT')
        WT_Mobility_ER = cat(1, WT_Mobility_ER, Mobility_and_ER_Data_Summary(n).Session2_Cell_ER_During_Mobility);
    end
end

WT_Immobility_ER = [];
for n = 1:size(Mobility_and_ER_Data_Summary,2)
    if isempty(WT_Immobility_ER) && strcmp(Mobility_and_ER_Data_Summary(n).genotype, 'a5-i-WT')
        WT_Immobility_ER = Mobility_and_ER_Data_Summary(n).Session2_Cell_ER_During_Imobility;
    elseif ~isempty(WT_Immobility_ER) && strcmp(Mobility_and_ER_Data_Summary(n).genotype, 'a5-i-WT')
        WT_Immobility_ER = cat(1, WT_Immobility_ER, Mobility_and_ER_Data_Summary(n).Session2_Cell_ER_During_Imobility);
    end
end

[WT_Mobility_ER_F, WT_Mobility_ER_X, ~, ~] = ecdf(WT_Mobility_ER,'Function','cdf','Alpha',0.05);
WT_Mobility_ER_X = cat(1, 0, WT_Mobility_ER_X, 1);
WT_Mobility_ER_F = cat(1, 0, WT_Mobility_ER_F, 1);
[WT_Immobility_ER_F, WT_Immobility_ER_X, ~, ~] = ecdf(WT_Immobility_ER,'Function','cdf','Alpha',0.05);
WT_Immobility_ER_X = cat(1, 0, WT_Immobility_ER_X, 1);
WT_Immobility_ER_F = cat(1, 0, WT_Immobility_ER_F, 1);

%% for a5-i-KO
KO_Mobility_ER = [];
for n = 1:size(Mobility_and_ER_Data_Summary,2)
    if isempty(KO_Mobility_ER) && strcmp(Mobility_and_ER_Data_Summary(n).genotype, 'a5-i-KO')
        KO_Mobility_ER = Mobility_and_ER_Data_Summary(n).Session2_Cell_ER_During_Mobility;
    elseif ~isempty(KO_Mobility_ER) && strcmp(Mobility_and_ER_Data_Summary(n).genotype, 'a5-i-KO')
        KO_Mobility_ER = cat(1, KO_Mobility_ER, Mobility_and_ER_Data_Summary(n).Session2_Cell_ER_During_Mobility);
    end
end

KO_Immobility_ER = [];
for n = 1:size(Mobility_and_ER_Data_Summary,2)
    if isempty(KO_Immobility_ER) && strcmp(Mobility_and_ER_Data_Summary(n).genotype, 'a5-i-KO')
        KO_Immobility_ER = Mobility_and_ER_Data_Summary(n).Session2_Cell_ER_During_Imobility;
    elseif ~isempty(KO_Immobility_ER) && strcmp(Mobility_and_ER_Data_Summary(n).genotype, 'a5-i-KO')
        KO_Immobility_ER = cat(1, KO_Immobility_ER, Mobility_and_ER_Data_Summary(n).Session2_Cell_ER_During_Imobility);
    end
end

[KO_Mobility_ER_F, KO_Mobility_ER_X, ~, ~] = ecdf(KO_Mobility_ER,'Function','cdf','Alpha',0.05);
KO_Mobility_ER_X = cat(1, 0, KO_Mobility_ER_X, 1);
KO_Mobility_ER_F = cat(1, 0, KO_Mobility_ER_F, 1);
[KO_Immobility_ER_F, KO_Immobility_ER_X, ~, ~] = ecdf(KO_Immobility_ER,'Function','cdf','Alpha',0.05);
KO_Immobility_ER_X = cat(1, 0, KO_Immobility_ER_X, 1);
KO_Immobility_ER_F = cat(1, 0, KO_Immobility_ER_F, 1);

%% plot graphs
figure
subplot(1,2,1)
plot(WT_Mobility_ER_X, WT_Mobility_ER_F, 'r', 'LineWidth', 3);
hold on
plot(WT_Immobility_ER_X, WT_Immobility_ER_F, 'b', 'LineWidth', 3);
xlim([0,0.4]);
xlabel('Event Rate (Hz)')
ylabel('Cumulative Fraction of Cells')
legend('Mobility (> 2cm/sec)', 'Immobility (< 2cm/sec)', 'Location', 'southeast')
set(gca, 'FontSize', 20)
title('p-WT', 'FontSize', 25)
hold off

subplot(1,2,2)
plot(KO_Mobility_ER_X, KO_Mobility_ER_F, 'r', 'LineWidth', 3);
hold on
plot(KO_Immobility_ER_X, KO_Immobility_ER_F, 'b', 'LineWidth', 3);
xlim([0,0.4]);
xlabel('Event Rate (Hz)')
ylabel('Cumulative Fraction of Cells')
legend('Mobility (> 2cm/sec)', 'Immobility (< 2cm/sec)', 'Location', 'southeast')
set(gca, 'FontSize', 20)
title('\alpha5-i-KO', 'FontSize', 25)
hold off

end